import javax.servlet.*;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: ttq
 * Date: 13-7-4
 * Time: 下午2:53
 * To change this template use File | Settings | File Templates.
 */
public class ExceptionHanlderFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } catch (Exception e) {
            Throwable rootCause = e;
            while (rootCause.getCause() != null) {
                rootCause = rootCause.getCause();
            }

            String message = rootCause.getMessage();
            message = message == null ? "异常:" + rootCause.getClass().getName() : message;
            request.setAttribute("message", message);
            request.setAttribute("e", e);

//            if (rootCause instanceof A)
        }
    }

    public void init(FilterConfig filterConfig) throws ServletException {
    }
}
